/**
 * desc: `routeTemplateMonitor` monitors each `$route` change and logs the
 *       current template via the `batchLog` service.
 * author: Joe
 * date: 7/20/2018
 */

coreModule.factory('routeTemplateMonitor',
  [
    '$rootScope', '$route', 'batchLog',
    function($rootScope, $route, batchLog) {
      var subscription = null;

      return {
        start: function() {
          subscription = $rootScope.$on('$routeChangeSuccess', function() {
            batchLog($route.current ? $route.current.loadedTemplateUrl : null);
          });
        },
        stop: function() {
          if (subscription) {
            subscription();
            subscription = null;
          }
        },
      };
    },
  ]
);
